home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 406_01 / atoc / getline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-09  |  979 b   |  45 lines

  1. /*========================================================================
  2.  
  3.     ATOC getline() module
  4.  
  5. =========================================================================*/
  6.  
  7. #include <stdio.h>
  8. #include "atoc.h"
  9.  
  10.  
  11. /*-------------------------------------------------------------------------
  12. getline( f, s ) gets a line from the file and puts it into s. \r\n is not
  13. put into s. Returns TRUE if ok or FALSE if EOF.
  14. -------------------------------------------------------------------------*/
  15. int getline( f, s )
  16. FILE *f;
  17. char *s;
  18. {
  19.     char *cp;
  20.     int c;
  21.  
  22.     cp = s;
  23.  
  24.     while ( ( c = getc( f ) ) != EOF )
  25.         switch( c )
  26.         {
  27.             case '\r':
  28.             case 0x1A:
  29.                 break;
  30.             case '\n':
  31.                 *cp = '\0';
  32.                 return( TRUE );
  33.             default:
  34.                 if ( cp < &s[ MAXLINELENGTH - 1 ] )
  35.                     *cp++ = c;
  36.                 break;
  37.         }
  38.  
  39.     *cp = '\0';
  40.     if ( cp > s )
  41.         return( TRUE );
  42.     else return( FALSE );
  43. }
  44. /*=======================================================================*/
  45.